package cn.springcloud.fix.common.log.condition;

import cn.springcloud.fix.common.log.annotation.EnableAsyncLog;
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * Created by yangjun on 2020/2/22.
 */
public class EnableAsyncLogCondition extends SpringBootCondition {

    @Override
    public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
        String[] enablers = context.getBeanFactory().getBeanNamesForAnnotation(EnableAsyncLog.class);
        ConditionMessage.Builder message = ConditionMessage.forCondition("@EnableAsyncLog Condition");
        if (enablers.length > 0) {
            return ConditionOutcome.match(message.foundExactly("@EnableAsyncLog annotation"));
        }
        return ConditionOutcome.noMatch(message.didNotFind("@EnableAsyncLog annotation").atAll());
    }
}
